package com.star.common.email.factory;

import com.star.common.email.config.EmailProperties;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * 生产Email实体
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/6/16 14:58
 */
public class EmailFactory {

    protected JavaMailSender javaMailSender(EmailProperties emailProperties) {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost(emailProperties.getHost());
        javaMailSender.setUsername(emailProperties.getUsername());
        javaMailSender.setPassword(emailProperties.getPassword());
        javaMailSender.setPort(emailProperties.getPort());
        javaMailSender.setDefaultEncoding(emailProperties.getDefaultEncoding().toString());
        Properties properties = new Properties();
        properties.putAll(emailProperties.getProperties());
        javaMailSender.setJavaMailProperties(properties);
        return javaMailSender;
    }
}
